package com.spring.framework.aop.annotation.introduction;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * 启动类
 *
 * @author xuweizhi
 * @since 2020/12/16 15:08
 */
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.spring.framework.aop.annotation.introduction")
public class AnnotationConfig {

	@Test
	public void aspectIntroduction() {
		//1 获取容器
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AnnotationConfig.class);
		//2.获取对象
		Object o = ac.getBean("basicFunction");
		System.out.println(o.getClass());
		System.out.println(o instanceof AddFunctionImpl);
		System.out.println(o instanceof AddFunction);
		System.out.println(o instanceof BasicFunction);
		System.out.println("------------");
		BasicFunction basicFunction=(BasicFunction) o;
		//3.尝试调用被代理类的相关方法
		basicFunction.get();
		basicFunction.update();
		//转换类型，调用新增的方法
		AddFunction addFunction=(AddFunction) basicFunction;
		addFunction.delete();
		addFunction.insert();
		System.out.println(AddFunction.str);
	}



}
